package com.Dao;


import java.sql.ResultSet;
import java.sql.SQLException;

import util.DBHelp;
import util.RowMapper;

import com.entity.Employee;
import com.entity.Project;
import com.entity.employProject;

public class employeeProjectDao {

	private DBHelp<employProject> db = new DBHelp<employProject>();
	
	
	public employProject findByProjectId(int projectid, int employeeid) {
		 StringBuilder sql = new StringBuilder();
		 
		 sql.append("SELECT `t_project`.`id`,`t_project`.`name`,`t_project`.`desc`,`t_project`.`createtime`,`t_employee`.`id`,`t_employee`.`username`,`t_employee`.`password`,`t_employee`.`supper` ,`t_employee_project`.`role`,`t_employee_project`.`projectid`,`t_employee_project`.`employeeid` FROM `t_project` ");
         sql.append("INNER JOIN `t_employee_project` ON `t_project`.`id` = `t_employee_project`.`projectid` ");
         sql.append("INNER JOIN `t_employee` ON `t_employee`.`id`=`t_employee_project`.`employeeid`");
         sql.append("WHERE `t_employee_project`.`projectid`=? AND `t_employee_project`.`employeeid`=?");
         return db.queryForObject(sql.toString(), new EmployeeProjectRowMapper(), projectid,employeeid);
 }
 
	private class EmployeeProjectRowMapper implements RowMapper<employProject> {

         public employProject mapperRow(ResultSet rs) throws SQLException {
                
        	 	employProject ep = new employProject();
                
                 ep.setRoal((rs.getString("role")));
                 
                 Employee e = new Employee();
                 e.setId(rs.getInt("id"));
                 e.setUsername(rs.getString("username"));
                 e.setPassword(rs.getString("password"));
                 e.setSupper(rs.getBoolean("supper"));
                 
                 ep.setProjectid(rs.getInt("projectid"));
                 ep.setEmployeeid(rs.getInt("employeeid"));
                 ep.setRoal(rs.getString("role"));
                 
                 Project p = new Project();
                 p.setCreatetime(rs.getString("createtime"));
                 p.setDesc(rs.getString("desc"));
                 p.setId(rs.getInt("id"));
                 p.setName(rs.getString("name"));
                 
                 ep.setProject(p);
                 ep.setProjectid(rs.getInt("projectid"));
                 
                 return ep;
         }
 	}



 
}
